// 将题目json数据放入数据库
import mongoose from 'mongoose'
import { resolve } from 'path'
import { writeFileSync } from 'fs'
// 创建房间。放置在数据库
const put_problem = async  () => {
  let data = require(resolve(__dirname, './terms.json'))
  const put_problem = mongoose.model('put_problem')
  for(let i =0; i<data.length; i++){
    let problem = new put_problem({
      problem_id: data[i].problem_id,
      problem: data[i].problem,
      problem_tip: data[i].problem_tip
    })
    await problem.save();
    
  }
  console.log('写入完毕')
}
const test = async () => {
  const put_problem = mongoose.model('put_problem')
  console.log('开始读取')
  const data = await put_problem.find({}).exec();
  console.log('读取完毕')
  writeFileSync('./terms.json', JSON.stringify(data, null, 2), 'utf-8')
  console.log(data.length,76666655)
}
test()

